package Server;

import java.io.IOException;
import java.util.StringTokenizer;

import javax.swing.JOptionPane;

import MetroMessenger.MessageProcesserConstants;
import MetroMessenger.SocketMessengerConstants;
import IO.File;

public class ServerMessageProcessor {
	static String output = "";

	static String process(String input) throws IOException {
		StringTokenizer inp = new StringTokenizer(input,
				SocketMessengerConstants.MESSAGE_SEPARATOR);

		if (inp.nextToken().contentEquals(MessageProcesserConstants.LOGIN)) {
			String Login, Password;
			StringTokenizer login = new StringTokenizer(inp.nextToken(), " ");
			Login = login.nextToken();
			Password = login.nextToken();
			// output = IO.authenicate(Login , Password );
			if (File.authenticate(Login, Password))
				output = Login + " "
						+ MessageProcesserConstants.AUTHENCIATEPASS;
			else
				output = Login + " "
						+ MessageProcesserConstants.AUTHENCIATEFAIL;
		}

		else if (inp.nextToken().contentEquals(MessageProcesserConstants.ADDTICKET)) 
		{
			String Login;
			StringTokenizer login = new StringTokenizer(inp.nextToken(), " ");
			Login = login.nextToken();
			JOptionPane.showMessageDialog(null, Login);
			output = Login + " " + MessageProcesserConstants.OK;
		}
		return output;
	}
}
